#!/usr/bin/python
import psycopg2
import sys
import pprint

def main():
    #start of script
    #Define our connection string
    conn_string = "host='localhost' dbname='versusdb' user='postgres' password='postgres'"
    # print the connection string we will use to connect
    print "Connecting to database\n    ->%s" % (conn_string)
    try:        
        conn = psycopg2.connect(conn_string)
        cursor = conn.cursor()
        print "Connected!\n"
        cursor.execute("SELECT * FROM product")
        records = cursor.fetchall()
        print "\nShow me the databases:\n"
        for row in records:
            print "   ", row[0], "    ", row[1] 
         
                 
    except:
        # Get the most recent exception
        exceptionType, exceptionValue, exceptionTraceback = sys.exc_info()
        # Exit the script and print an error telling what happened.
        sys.exit("Database connection failed!\n ->%s" % (exceptionValue))


if __name__ == "__main__":
    sys.exit(main())